package com.platform.modules.mall.activity.type;

import com.platform.common.utils.JedisUtil;
import com.platform.modules.mall.entity.MallGoodsToActivityEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;


@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Component
public class PollingGoodsType extends ActivityTypeAbstract{

    @Autowired
    private JedisUtil jedisUtil;

    private static final String KEY="PollingGoodsUtil_Index";
    private String activityId;

    public void setData(String activityId){
        this.activityId =activityId;
    }

    @Override
    public MallGoodsToActivityEntity getEntity() {
        Long incr = jedisUtil.incr(KEY+this.activityId);
        long index =incr % entityList.size();
        MallGoodsToActivityEntity goods = entityList.get((int) index);
        return goods;
    }
}
